//
//  DeviceToConnect.h
//  360 Audio
//
//  Created by user on 16/9/6.
//  Copyright © 2016年 com. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <ExternalAccessory/ExternalAccessory.h>



#define BREAK   @"123"

typedef NS_ENUM(NSInteger,linkSteta){
    
    AreConnected = 0 ,
    IsConnected ,
};

typedef NS_ENUM(NSInteger,ljzt) {
    zt1=-1,
    zt2,
    zt3,
};

@protocol DeviceToConnectDelegate <NSObject>

@required
/**
 *  设备已经连接回调
 */
-(void)isDeviceToConnect;

/**
 *  设备断开连接回调
 */
-(void)undeviceToConnect;

@optional

-(void)beginToConnect;

-(void)getTextView:(NSString *)str;

/**
 *  获取安装进度
 */
-(void)getProgressView:(float)numbel;
-(void)getProgressView:(float)numbel cmunbel:(NSInteger)cnumbel tmunbel:(NSInteger)tnmubel index:(NSInteger)index;

-(void)lastObjcet:(NSString *)str;

-(void)thereWasAnErrorInstallingTheUpdate:(NSString *)errorString;

/**
 发现设备且核对信息
 */
-(void)foundEquipmentAndCheckTheInformation;


/**
 已经是最新版本
 */
-(void)isTheLatestVersion;
-(void)isNotTheLatestVersion;



@end

@interface DeviceToConnect : NSObject<EAAccessoryDelegate,NSStreamDelegate>
{
    
        
    NSInputStream * _inputStream;
        
    NSData *_readData;
    NSInteger numFlag;
    NSInteger _dataCount;
    NSInteger _CurrentCount;
    BOOL version;
    BOOL eqstateFlag;
    
}
@property(nonatomic) id<DeviceToConnectDelegate> delegate;

@property (strong, nonatomic)EASession * session;
//@property (nonatomic, strong)EAAccessory * MCUsession;

@property (nonatomic ,strong) NSMutableArray *accessories;
@property (nonatomic, strong) NSMutableArray *datas;
@property (nonatomic,strong) NSString *protocolString;
@property (nonatomic,strong) NSString *productNameString;
@property (nonatomic,strong) NSString *modeNameString;

/**
 获取到的耳机固件版本
 */
@property (nonatomic,strong) NSString *versionString;

/**
 所要升级到的版本
 */
@property (nonatomic,strong) NSString *latestVersion;
@property (nonatomic,assign) NSInteger eqstate;
@property (nonatomic,assign) BOOL shouldInstall;    // 请求得来可否安装
@property (nonatomic,assign) BOOL reciveOK;         // 表示MCU接到刚发送的数据包
@property (nonatomic,assign) int index;             // 安装数据包的index
@property (nonatomic,assign) BOOL userAllowWrite;   // 仅表示用户批准安装
@property (nonatomic,assign) BOOL startInstallation;// 已经开始安装
@property (nonatomic,assign) BOOL flag;
@property (nonatomic,strong) NSString *iphoneVersion; //手机系统版本号，只取大版本

+ (DeviceToConnect *)sharedController;

/**
 *  设备连接通知
 */

-(BOOL)addNotice;

/**
 *  设备连接后，进行通信连接
 */
- (NSInteger)openSessionForProtocol:(NSString *)protocolString andIsEqualToProductName:(NSString *)productNameString andeModeName:(NSString *)modeNameString  andVersion:(NSString *)versionString;
/**
 *  获取连接设备的信息
 */
-(NSDictionary *)equipmentInformation;

/**
 *  再次连接设备
 */
-(BOOL)connectAgain;

/**
 *  开始安装
 */
-(void)update;

-(void)eqController:(NSInteger ) num;

-(BOOL)findEQlocation;

@end
